package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.DictionaryItem;
import cn.wolfcode.crm.mapper.DictionaryItemMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDictionaryItemService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DictionaryItemServiceImpl implements IDictionaryItemService {
    @Autowired
    private DictionaryItemMapper dictionaryItemMapper;

    @Override
    public void deleteByPrimaryKey(Long id) {
        dictionaryItemMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(DictionaryItem entity) {
        if (entity.getId() == null) {
            dictionaryItemMapper.insert(entity);
        } else {
            dictionaryItemMapper.updateByPrimaryKey(entity);
        }
    }


    @Override
    public DictionaryItem selectByPrimaryKey(Long id) {
        return dictionaryItemMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<DictionaryItem> selectAll() {
        return dictionaryItemMapper.selectAll();
    }


    @Override
    public PageResult query(QueryObject qo) {
        Integer total = dictionaryItemMapper.query4Count(qo);
        if (total == 0) {
            return PageResult.PAGERESULT_EMPTY;
        }
        return new PageResult(total, dictionaryItemMapper.query4List(qo));
    }

    @Override
    public List<DictionaryItem> getItemBySn(String sn) {
        return dictionaryItemMapper.getItemBySn(sn) ;
    }
}
